<template>
    <div :style="styleExternalIcon" :title="$attrs.title" class="svg-external-icon svg-icon" v-on="$listeners" />
    <!-- <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners">
      <title v-if="$attrs.title">{{ $attrs.title }}</title>
      <use :xlink:href="iconName" />
    </svg> -->
  </template>
  <script>
  /**
   * @group 单个组件的封装 mc-ui
   * 参考doc: https://panjiachen.github.io/vue-element-admin-site/feature/component/svg-icon.html#usage
   */
  export default {
    props: {
      // 实际生效对应的icon name
      iconClass: {
        type: String,
        required: true
      },
      // svg 添加的className
      className: {
        type: String,
        default: ''
      }
    },
    computed: {
      iconName () {
        return `#icon-${this.iconClass}`
      },
      svgClass () {
        if (this.className) {
          return 'svg-icon ' + this.className
        } else {
          return 'svg-icon'
        }
      },
      styleExternalIcon () {
        return {
          mask: `url(${this.iconClass}) no-repeat 50% 50%`,
          '-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`
        }
      }
    }
  }
  </script>
  
  <style scoped lang="scss">
  .svg-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
  }
  
  .svg-external-icon {
    background-color: currentColor;
    mask-size: cover!important;
    display: inline-block;
  }
  </style>
  